﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace hamster
{
    class Rock : WorldObject
    {
        public const int ROCK_MAX_HEALTH = 6;
        public const float BREAK_SPEED = .5f;
        int rockHealth_;

        public Rock(Vector2 position, float rotation, ObjectPlacer parent) : base(position, rotation, parent)
        {
            debugColor_ = Color.Gray;
            rockHealth_ = ROCK_MAX_HEALTH;
        }

        public override bool Update(float dt, Player player)
        {
            base.Update(dt, player);
            // If the player hits the fruit, eat it
            if (boundingBox_.Intersects(player.boundingBox))
            {
                Vector2 relDir = Vector2.Subtract(position_, new Vector2(player.position.X, player.position.Y));
                relDir = Vector2.Transform(relDir, Matrix.CreateRotationZ(-rotation_));

                player.position = player.oldPosition;
                if (player.velocity.Length() >= BREAK_SPEED)
                {
                    rockHealth_--;
                    // TODO Play a cracking sound.
                }
                player.velocity.X *= -.7f;
            }

            if (rockHealth_ <= 0)
                return true;

            return false;
        }
    }
}
